import { MyVue } from 'src/wl/my_vue';
import Vue from 'vue';
import { Component, Emit, Prop, Provide, Watch } from 'vue-property-decorator'
import { auditManageConst } from "src/consts/audit_manage_const";
import * as Api from 'src/api/net';

@Component({})
export default class AuditMStatusPanel extends MyVue {
    name: string = 'AuditMStatusPanel';
    formData: any;
    footerFlag: boolean;
    webData: any;

    initData(that?: any): void {
        that.formData = WLStore().state.auditMStatus;
        that.webData = WLStore().state.auditManage.data_list[that.formData.index]
        if (that.formData.status == "pass" || that.formData.status == "refuse") {
            that.footerFlag = false
        } else {
            that.footerFlag = true
            var flag = false

            if (that.webData.curNode && isNoEmpty(that.webData.curNode.user_list)) {
                for (let k = 0; k < that.webData.curNode.user_list.length; k++) {
                    if (getUserInfo().userId == that.webData.curNode.user_list[k].id) {
                        flag = true
                    }
                }
            }

            if (!flag) {
                that.footerFlag = false
                return
            }
        }
    }

    mounted(): void {
    }

    editAudit(): void {
        var idArr = []
        idArr.push(this.webData)
        WLCommit(auditManageConst.CommitType, idArr)
    }

    rowShow(): void {
        let senData: any = {}
        senData["entity_id"] = this.webData.entity_id
        senData["model"] = this.webData.model
        WLDispatch(auditManageConst.DispatchAuditMShow, senData);
    }


    setIcon(status: string, index: Number): String {
        var icon = ""
        if (status == "pass") {
            icon = "btn_qy"
        } else if (status == "checking") {
            icon = "shz2"
        } else if (status == "refuse") {
            icon = "btn_qs"
        } else if (status == "wait") {
            icon = "dd"
        } else {
            icon = "fq2"
        }

        return icon
    }


    setTime(item: any, index: Number): String {
        var date: String = ""
        if (index == 0 || item.status == "checking") {
            date = timestampToTime(item.start_time)
        } else if (item.status == "wait") {
            date = "    "
        } else {
            date = timestampToTime(item.end_time)
        }

        return date
    }

    setName(name: string): String {
        var val = ""
        if (name) {
            val = name
        } else {
            val = "上级领导"
        }

        return val
    }

    setVal(status: string): String {
        return getValueByKey("audit_status", status)
    }

    setStatus(status: string, index: Number): String {
        var val = ""
        if (index == 0) {
            val = "发起人"
        } else {
            val = getValueByKey("audit_status", status)
        }

        return val
    }
}